<template>
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <div class="search-wrap">
      <a-form-model ref="formRef">
        <a-row>
          <a-col :span="6">
            <div style="margin-right: 12px">
              <a-form-model-item prop="bar"
                ><a-input v-model="bar" placeholder="请输入英克码" allowClear />
              </a-form-model-item>
            </div>
          </a-col>
          <a-col :span="6" style="margin-top: 5px">
            <a-button style="margin-right: 20px" @click="searchQuery()" type="primary"> 查询 </a-button>
            <!-- <a-button style="margin-right: 20px" @click="searchReset()"> 重置 </a-button> -->
          </a-col>
        </a-row>
      </a-form-model>
    </div>
    <!-- 查询区域-END -->

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{ x: true }"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataList"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        class="j-table-force-nowrap"
        @change="handleTableChange2"
      >
      <!-- 处理状态 -->
        <template slot="blState" slot-scope="text, record">
          <span>{{ getBlState(record.blState) }}</span>
        </template>
        <!-- 槽 渲染 指定 cloumn的值 -->
        <template slot="state" slot-scope="text, record">
          <a-tag :color="onColor(text.state,record)">
            {{ getOrderState(text.state,record) }}
          </a-tag>
        </template>

      

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">补录</a>
          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>

              <!-- <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item> -->
            </a-menu>
          </a-dropdown>
        </span>
      </a-table>
    </div>
    <yk-code-modal ref="modalForm" @ok="modalFormOk1"></yk-code-modal>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import YkCodeModal from './YkCodeModal'

import { queryOrderDetailList } from '@/api/warehouse'
import { getAction } from '@/api/manage'

import { mapState } from 'vuex'

export default {
  name: 'YkCodeList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    YkCodeModal,
  },
  data() {
    return {
      // description: 'wms_bar_bind_order管理页面',
      dataList:[],
      bar:'',
      // 表头
      columns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '英克码',
          align: 'center',
          dataIndex: 'bar',
        },
        {
          title: 'UDI',
          align: 'center',
          dataIndex: 'udi',
        },
        {
          title: '处理状态',
          align: 'center',
          dataIndex: 'blState',
          //筛选条件编辑
          filters: [
            {
              text: '已处理',
              value: '1',
            },
            {
              text: '待处理',
              value: '0',
            },
          ],
          filterMultiple: false,

          onFilter: (value, record) => {
            return record.blState == value
          },
          scopedSlots: { customRender: 'blState' },
        },
        {
          title: '状态',
          align: 'center',
          scopedSlots: { customRender: 'state' },
        },

        {
          title: '创建时间',
          align: 'center',
          dataIndex: 'createTime',
        },

        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: '',
        delete: '/wms/wmsBarBindOrderDetail/delete',
        deleteBatch: '/wms/wmsBarBindOrderDetail/deleteBatch',
        // exportXlsUrl: "/wms/wmsBarBindOrder/exportXls",
        // importExcelUrl: "wms/wmsBarBindOrder/importExcel",
      },
      dictOptions: {},
      superFieldList: [],
    }
  },
  created() {
  },
  mounted() {
    this.$store.commit('getEnableWarehouse')
  },
  computed: {
    ...mapState({
      enableWarehouse: (s) => s.dictionary.enableWarehouse,
    }),
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    async edit(record) {
        
        try {
        const params = { orderNo: record.orderNo }
        const r = await queryOrderDetailList(params)
        if (r.result.total) {
              this.ipagination.total = r.result.total
            }
        this.dataList = r.result.records
        this.orderNo = record.orderNo
      } catch (err) {
        console.log(err);
      }

    },
    handleTableChange2(pagination, filters, sorter) {
      console.log(pagination, filters, sorter);
      this.ipagination.current = pagination.current
      this.ipagination.pageSize = pagination.pageSize
      this.loadData1()
    },

    loadData1(arg) {
      //加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1
      }
      getAction('/wms/wmsBarBindOrderDetail/list', {
        bar:this.bar,
        orderNo:this.orderNo,
        pageNo:this.ipagination.current,
        pageSize: this.ipagination.pageSize
      })
      
        .then((res) => {
          if (res.success) {
            //update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
            this.dataList = res.result.records || res.result
            if (res.result.total) {
              this.ipagination.total = res.result.total
            } else {
              this.ipagination.total = 0
            }
            //update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          } else {
            this.$message.warning(res.message)
          }
        })
        .finally(() => {
          this.loading = false
        })
    },

    searchQuery() {
      this.loadData1(1)
      // 点击查询清空列表选中行

      this.selectedRowKeys = []
      this.selectionRows = []
    },

    modalFormOk1() {
      // 新增/修改 成功时，重载列表
      this.loadData1()
      //清空列表选中
      this.onClearSelected()
    },

    getBlState(state) {
      if (state == '0') {
        return '待处理'
      } else if (state == '1') {
        return '已处理'
      }
    },

    getOrderState(state,record) {
      if(record.blState == '1') {
        return '完成'
      } else {
        return '待补录'
      }
    },
    

    // 状态颜色
    onColor(text,record) {
      let color = ''
      if(record.blState == '1') {
        color = 'green'
      } else {
        color = 'red'
      }
    
      return color
    },

    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'orderNo', text: '订单号' })
      fieldList.push({ type: 'string', value: 'orderType', text: '订单类型' })
      fieldList.push({ type: 'string', value: 'state', text: '状态' })
      fieldList.push({ type: 'int', value: 'sums', text: '数量' })
      fieldList.push({ type: 'string', value: 'warehourse', text: '所属仓库' })
      this.superFieldList = fieldList
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
<style scoped lang="scss">
::v-deep .ant-modal-footer{
  text-align: left;
}
</style>